﻿using System;

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.ConsoleTraceListener());

            Console.ForegroundColor = ConsoleColor.Cyan;
            System.Diagnostics.Trace.WriteLine("Program executing...");

            ServiceReferences.PersonService.PersonRequest request = new ServiceReferences.PersonService.PersonRequest { Person = new ServiceReferences.PersonService.Person() };
            request.Person.Name = "Chris";
            request.Person.Birthday = new DateTime(1979, 9, 10);
            ServiceReferences.PersonService.PersonResponse response = null;

            using (ServiceReferences.PersonService.PersonServiceClient client = new ServiceReferences.PersonService.PersonServiceClient())
            {
                try
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    System.Diagnostics.Trace.WriteLine("Saving person...");
                    response = client.SavePersonRecord(request);

                    Console.ForegroundColor = ConsoleColor.Green;
                    System.Diagnostics.Trace.WriteLine(String.Format("Response from Instance Id: {0}", response.InstanceId));
                    System.Diagnostics.Trace.WriteLine(String.Format("Response Message: {0}", response.Message));
                    System.Diagnostics.Trace.WriteLine(null);

                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    System.Diagnostics.Trace.WriteLine("Deleting person...");
                    response = null;
                    response = client.DeletePersonRecord(request);
                    Console.ForegroundColor = ConsoleColor.Green;
                    System.Diagnostics.Trace.WriteLine(String.Format("Response from Instance Id: {0}", response.InstanceId));
                    System.Diagnostics.Trace.WriteLine(String.Format("Response Message: {0}", response.Message));
                }
                catch (Exception ex)
                {
                    client.Abort();
                    Console.ForegroundColor = ConsoleColor.Red;
                    System.Diagnostics.Trace.WriteLine(String.Format("Exception occurred: {0}", ex.ToString()));
                }
            }

            Console.ForegroundColor = ConsoleColor.Cyan;
            System.Diagnostics.Trace.WriteLine("Execution complete...press <enter> to exit");
            Console.ReadLine();
        }
    }
}
